<?php echo $header; ?>
<div class="box">
    <div class="content">
        <h2 class="h2title">New Document</h2>
        <div>
            <div class="warning" style="margin-top:10px;display:none;">
            </div>
            <table style="width:100%;padding:20px;">
                <tr>
                    <td align="right">
                        <span class="spanlablebold" style="margin-right:5px;">Document No</span>
                    </td>
                    <td>
                        <input type="text" id="txtdocno" name="txtdocno" class="txt" maxlength="50"/>
                    </td>
                    <td align="right">
                        <span class="spanlablebold" style="margin-right:5px;">Date</span>
                    </td>
                    <td>
                        <input type="text" id="txtdocdate" value="<?php echo date('m/d/y'); ?>" name="txtdocdate" class="txt" disabled="true"/>
                    </td>
                    <td align="right">
                        <span class="spanlablebold" style="margin-right:5px;">Time</span>
                    </td>
                    <td>
                        <input type="text" id="txtdoctime" name="txtdoctime" value="<?php echo $stime; ?>" class="txt" disabled="true"/>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <span class="spanlablebold" style="margin-right:5px;">Document Type</span>
                    </td>
                    <td>
                        <select id="seldoctype" class="sel" style="width: 205px;">
                            <option value="">--select--</option>
                            <?php if(count($doctype_list)>0){
						foreach($doctype_list as $row){ ?>
                            <option value="<?php echo $row["docuementtype_id"]; ?>">
                                <?php echo $row["name"]; ?>
                            </option>
                            <?php }}?>
                        </select>
                    </td>
                    <td align="right">
                        <span class="spanlablebold" style="margin-right:5px;">From</span>
                    </td>
                    <td>
                        <input type="text" id="txtfrom" name="txtfrom" class="txt"/>
                    </td>
                    <td align="right">
                        <span class="spanlablebold" style="margin-right:5px;">Reference No</span>
                    </td>
                    <td>
                        <input type="text" id="txtrefno" name="txtrefno" class="txt"/>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <span class="spanlablebold" style="margin-right:5px;">Issue Date</span>
                    </td>
                    <td>
                        <input type="text" id="txtissuedate" name="txtissuedate" class="txt"/>
                    </td>
                    <td align="right">
                        <span class="spanlablebold" style="margin-right:5px;">Addressed To</span>
                    </td>
                    <td>
                        <input type="text" id="txtadddressedto" name="txtadddressedto" class="txt"/>
                    </td>
                    <td align="right">
                        <span class="spanlablebold" style="margin-right:5px;">Receipt Date</span>
                    </td>
                    <td>
                        <input type="text" id="txtreceiptdate" name="txtreceiptdate" class="txt"/>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <span class="spanlablebold" style="margin-right:5px;">Receipt Time</span>
                    </td>
                    <td>
                        <input type="text" id="txtreceipttime" name="txtreceipttime" class="txt"/>
                    </td>
                    <td align="right">
                        <span class="spanlablebold" style="margin-right:5px;">Data Entered By</span>
                    </td>
                    <td>
                        <input type="text" id="txtdataenteredby" value="<?php echo $this->user->getFirstName(); ?>" name="txtdataenteredby" class="txt" disabled="true"/>
                    </td>
                    <td align="right">
                        <span class="spanlablebold" style="margin-right:5px;">Department</span>
                    </td>
                    <td>
                        <select id="seldeptid" disabled="true" class="sel" style="width: 205px;">
                            <option value="">--select--</option>
                            <?php foreach($dept_list as $row){
							$selclass="";
							if($row["department_id"]==$this->user->getDepartmentId()){
							$selclass="selected";
							} 
							?>
                            <option value="<?php echo $row["department_id"]; ?>"
                                <?php echo $selclass;?>
                                >
                                <?php echo $row["name"]; ?>
                            </option>
                            <?php } ?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td align="right" valign="top">
                        <span class="spanlablebold" style="margin-right:5px;">Remark</span>
                    </td>
                    <td>
                        <textarea id="txtarearemark" name="txtarearemark" rows="3" cols="31">
                        </textarea>
                    </td>
                    <td colspan="4">
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>
<div class="buttonbar">
    <input type="button" value="Save" id="btnsave" name="btnsave" class="btnradius" style="margin-right:10px;"/><input type="button" value="Reset" id="btnreset" name="btnreset" class="btnradius"/>
</div>
<script type="text/javascript">
    
    $("#txtissuedate,#txtreceiptdate").datepicker({
        changeMonth: true,
        changeYear: true
    });
    
    $('#txtreceipttime').timepicker({
        'timeFormat': 'H:i:s',
        'step': 5
    });
    
    
    $("#btnsave").click(function(){
        if (validate()) {
            loading("show");
            $.ajax({
                url: "<?php echo MAIN_PAGE.'docupload/docuploadpost';?>",
                type: 'POST',
                data: {
                    docno: $("#txtdocno").val(),
                    docdate: $("#txtdocdate").val(),
                    doctime: $("#txtdoctime").val(),
                    doctypeid: $("#seldoctype").val(),
                    from: $("#txtfrom").val(),
                    refno: $("#txtrefno").val(),
                    issuedate: $("#txtissuedate").val(),
                    addressedto: $("#txtadddressedto").val(),
                    receiptdate: $("#txtreceiptdate").val(),
                    receipttime: $("#txtreceipttime").val(),
                    dataenteredby: $("#txtdataenteredby").val(),
                    deptid: $("#seldeptid").val(),
                    remark: $("#txtarearemark").val()
                },
                dataType: 'json',
                success: function(res){
                    loading('hide');
                    if (res.status) {
                        alert(res.msg);
                        $("#btnreset").trigger("click");
                    }
                    else {
                        alert(res.msg);
                    }
                }
            });
        }
    });
    
    $("#btnreset").click(function(){
        $(".warning").hide();
        var txtarr = ["txtdocno", "txtfrom", "txtrefno", "txtissuedate", "txtadddressedto", "txtarearemark", "txtreceipttime", "txtreceiptdate"];
        for (var i = 0; i < txtarr.length; i++) {
            $("#" + txtarr[i]).val("");
        }
        $("#seldoctype option:first").attr('selected', 'selected');
        var now = new Date();
        $("#txtdocdate").val(now.format("mm/dd/yy"));
        $("#txtdoctime").val(now.format("isoTime"));
        // $("#seldeptid option:first").attr('selected', 'selected');
    });
    
    
    function validate(){
        $(".warning").hide();
        if ($("#txtdocno").val() == "") {
            $("#txtdocno").focus();
            $(".warning").text("Please enter Document No").show();
            return false;
        }
        if ($("#txtdocdate").val() == "") {
            $("#txtdocdate").focus();
            $(".warning").text("Please enter Date").show();
            return false;
        }
        if ($("#txtdoctime").val() == "") {
            $("#txtdoctime").focus();
            $(".warning").text("Please enter Time").show();
            return false;
        }
        if ($("#seldoctype").val() == "") {
            $("#seldoctype").focus();
            $(".warning").text("Please choose Document Type").show();
            return false;
        }
        if ($("#txtfrom").val() == "") {
            $("#txtfrom").focus();
            $(".warning").text("Please enter From").show();
            return false;
        }
        if ($("#txtrefno").val() == "") {
            $("#txtrefno").focus();
            $(".warning").text("Please enter Reference No").show();
            return false;
        }
        if ($("#txtissuedate").val() == "") {
            $("#txtissuedate").focus();
            $(".warning").text("Please enter Issue Date").show();
            return false;
        }
        if ($("#txtadddressedto").val() == "") {
            $("#txtadddressedto").focus();
            $(".warning").text("Please enter Addressed To").show();
            return false;
        }
        if ($("#txtreceiptdate").val() == "") {
            $("#txtreceiptdate").focus();
            $(".warning").text("Please enter Receipt Date").show();
            return false;
        }
        if ($("#txtreceipttime").val() == "") {
            $("#txtreceipttime").focus();
            $(".warning").text("Please enter Receipt Time").show();
            return false;
        }
        if ($("#txtdataenteredby").val() == "") {
            $("#txtdataenteredby").focus();
            $(".warning").text("Please enter Data Entered By").show();
            return false;
        }
        if ($.trim($("#txtarearemark").val()) == "") {
            $("#txtarearemark").focus();
            $(".warning").text("Please enter Remark").show();
            return false;
        }
        return true;
    }
</script>
<?php echo $footer;?>
